﻿<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>阻止表单的提交</title>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		$("#subbtn").bind("click",function(event){
			var username = $("#username").val();
			if(username == ""){
				alert("用户名不能为空！");  // 弹出提示信息
				$("#username").focus();      // 将焦点移至文本框中
				event.preventDefault();      // 阻止表单提交的默认行为
			}
		})
	});
	</script>
</head>
<body>
<form action="index.html" method="post">
	用户名：<input type="text" id="username" /><br/>
	<input type="submit" value="注册" id="subbtn" />
</form>
</body>
</html>
